/*
 * CavansWelcome.cpp
 *
 *  Created on: 2013-1-23
 *      Author: heqiu
 */

#include "Global.h"

CanvasWelcome::CanvasWelcome(uint32_t uiShortUnit, uint32_t uiLongUnit,
		uint32_t uiUnitPixel) :
		GuudCanvas(uiShortUnit, uiLongUnit, uiUnitPixel) {
	m_button_exit.setFuncPressed(pressed_button_exit);
	m_button_begin.setFuncPressed(pressed_button_begin);
	m_button_save.setFuncPressed(pressed_button_save);
}

void CanvasWelcome::draw() {
	if (m_bShow) {
		GuudPoint stPoint = m_gpScreenPosPixel;
		//stPoint.m_iY += 100;
		g_GlobalData.m_pGuudScreen->drawButton(stPoint, m_button_begin);
		stPoint.m_iY += 100;
		g_GlobalData.m_pGuudScreen->drawButton(stPoint, m_button_exit);
		stPoint.m_iY += 100;
		g_GlobalData.m_pGuudScreen->drawButton(stPoint, m_button_save);
		/*
		 g_GlobalData.m_pGuudScreen->drawCoordinate(m_gpScreenPosPixel,
		 g_GlobalData.m_GuudFont);
		 */
	}
}
void CanvasWelcome::init() {
	m_gpScreenPosPixel.m_iX = g_GlobalData.m_config_game.getKKValueInt32(
			"welcome-canvas", "x-pixel");
	m_gpScreenPosPixel.m_iY = g_GlobalData.m_config_game.getKKValueInt32(
			"welcome-canvas", "y-pixel");
	string sFileName = "./image/button.png";
	bool bFlag = m_GuudSurface_welcome.loadImage(sFileName.c_str());
	if (!bFlag) {
		g_GlobalData.m_GuudLog.log("[%s][%d]错误:图片 %s 加载失败", __FILE__, __LINE__,
				sFileName.c_str());
		exit(-1);
	}
	GuudRect rectIn;
	GuudRect rectOut;
	GuudRect rectPressed;
	rectIn.w = 210;
	rectIn.h = 60;
	rectOut.w = 210;
	rectOut.h = 60;
	rectPressed.w = 210;
	rectPressed.h = 60;
	rectOut.x = 0;
	rectOut.y = 0;
	rectIn.x = 210;
	rectIn.y = 0;
	rectPressed.x = 420;
	rectPressed.y = 0;
	m_button_begin.setSurface(&m_GuudSurface_welcome, rectIn, rectOut,
			rectPressed);
	rectOut.y = 60;
	rectIn.y = 60;
	rectPressed.y = 60;
	m_button_exit.setSurface(&m_GuudSurface_welcome, rectIn, rectOut,
			rectPressed);
	rectOut.y = 120;
	rectIn.y = 120;
	rectPressed.y = 120;
	m_button_save.setSurface(&m_GuudSurface_welcome, rectIn, rectOut,
			rectPressed);
	m_bListen = true;
}

void CanvasWelcome::handleEvent(GuudEvent &stEvent) {
	if (m_bListen) {
		GuudPoint stPoint = m_gpScreenPosPixel;
		m_button_begin.handleEvent(stPoint, stEvent, this);
		stPoint.m_iY += 100;
		m_button_exit.handleEvent(stPoint, stEvent, this);
		stPoint.m_iY += 100;
		m_button_save.handleEvent(stPoint, stEvent, this);
	}
}

